02-28-24 (Wednesday)

Let us confess to God those things that are wrong in our work:
That the presence of God at work is often overlooked;
That creative people are often subjected to long, boring and unrelenting routines;
That skills are undeveloped through lack of training;
That resources are wasted in shoddy work and the production of unwanted goods;
That the maximisation of profit often excludes concern for people;
That men and women are discriminated against because of age, race, gender, disability, lack of skill and length of employment;
That the poor stand so little chance against the power of the rich, and the world’s destitute are forgotten.

Lord, have mercy upon us. Forgive us our sins and help us to amend our lives. Amen.
(https://www.theologyofwork.org/work-in-worship)

1 Object-Oriented Programming

  • Originally, computers were designed for just running algorithms for performing specific tasks.
  • With the invention of operating systems, databases and graphical user interfaces, however, programming took a turn toward representing objects virtually and interacting with them.
  • For achieving that, we needed a new way of articulating programming and programming languages: the Object-Oriented Paradigm.

1.1 Classes and objects

  • We define classes, which are basically “blueprints” for the objects (or, you could say, type definitions)
    • We instantiate an object of some class by just writing the class name with parenthesis - like Dog()
  • These classes define attributes (variables) and methods (functions) for an object of its type.

class Dog(): # definition of the class ("blueprint")
  
  # indentation starts - "inside of class"
  def eat(self):  # a method (NOTICE THAT IT IS INSIDE THE CLASS DEFINITION)
    pass  # using "pass" to write it as an empty function (to be filled later)
  
  def sleep(self):
    pass
  
  def sit(self):
    pass


# main code chunk! (outside of class definition now)
a = Dog()  # creates an instance of type "Dog"
a.breed = 'Pug'  # its breed (attribute) is 'Pug"
b = Dog()
b.breed = 'Boxer'

1.2 Example: the Turtle class

  • Remember the turtles we are using to draw? They are also objects of class Turtle.
import turtle
raphael = turtle.Turtle() # creates a turtle
leonardo = turtle.Turtle() # creates another turtle
print(raphael.pos) # gets the attribute "position" of the turtle Raphael
leonardo.forward(100) # calls the method "forward" for the turtle Leonardo

1.3 Some principles and rules

  • PEP-8 style guidelines require that we write the names of classes starting with capital letters! (e.g., Dog, Car, Player, etc.).
    • This helps A LOT differentiating them from functions (like eat(), sleep(), etc.) and variables (like a, b, etc.).
  • The Single Responsibility Principle states that every class should have one and only one responsibility. All class attributes and methods should be aligned with that one responsibility.
    • This helps organize classes and makes changes easier.
    • As a class grows, it may need to be split (a process that is part of what we call refactoring).

2 Constructor method: __init__()

  • The special method __init__ is important in almost class. It is called the constructor method and runs automatically when user instantiates an object.
  • It is important to include the self parameter - this refers to the object itself!
class Dog(): # definition of the class ("blueprint")
  
  def __init__(self, breed, age, color):
    self.breed = breed
    self.age = age
    self.color = color
    
    
# main code chunk
a = Dog('pug', 3, 'black')
b = Dog('boxer', 2, 'white')
print(a.breed)
pug

3 The self argument

  • Everytime you want to reference an attribute of the object inside of a class method, you call self

  • For example, what is self referring to in this example?

class Dog():
  
  def crossbreed(self, dog):
    if self.breed == dog.breed:
      puppy = Dog(self.breed,0,Dog.average_color(self.color, dog.color))
    else:
      puppy = Dog('mutt',0,Dog.average_color(self.color, dog.color))
    return puppy

4 Class methods and variables

  • You can declare variables and methods that are pertaining to the class itself, not to specific instances. In that case, you just don’t use the parameter self.

  • To use those, you don’t call the method on the object (like x.method()), but on the class itself (like Dog.average_color).

  • Following our last example:

class Dog():
  
  max_age = 20
  
  def average_color(c1, c2):
    return c1 + ' and ' + c2


print(Dog.max_age)
print(Dog.average_color('black','white'))
20
black and white

5 The __str__ method

  • This method is usually implemented to returns a string representation of an object’s state.
    • Attention: you don’t “print”, you just return a string!
    • When you call “print” with your object, it will “convert” it to a string representation
class Dog():
  
  def __str__(self):
    return f'breed: {self.breed}, age: {self.age}, color: {self.color}'
  
a = Dog()
a.breed = 'boxer'
a.age = '2'
a.color = 'white'
print(str(a))
print(a)
breed: boxer, age: 2, color: white
breed: boxer, age: 2, color: white

6 Exercise: a card game

Try to write the class definitions for the following class diagram, representing a game of bridge:

7 The internet of things

With the advent of this digital object as the standard way to process data across computer applications, came the idea of connecting all these objects in a worldwide network. This is the idea of Tim Berners-Lee, the creator of the HTML standard, who wrote in his book “Weaving the Web”:

“Suppose all the information stored on computers everywhere were linked, I thought. Suppose I could program my computer to create a space in which anything could be linked to anything. All the bits of information in every computer at CERN, and on the planet would be available to me and to anyone else. There would be a single , global information space.”

Yuk Hui, a philosopher of technology, understands that this could mean the total representation of the world as data and connection between these elements in order to give control to humans over reality. It is what he calls interobjectivity:

The development of data schemes, ontologies, and protocols brings objects and users closer to each other and shortens the temporal and geographical distance involved in information acquisition. It brings us a new convergence by which we can talk about the internet of things, social media, and so on. This totality we can call a technical system. (…) The ultimate expression of interobjectivity is the formation of technical systems that traverse all spatial and temporal obstacles. - Yuk Hui, “On the existence of digital objects”, 2016

Hui also understands that this means the totalization of the information system. We thus enter in the information age.

  • What are the consequences of this?

7.1 The interface bottleneck

  • Every meaningful action in the world is thus mediated by the interface: screens, spreadsheets, programming…
    • This change is observed today in education (method and curriculum), science, work in general.

7.2 A hyperreal society

  • Albert Borgmann, following Jean Baudrillard, calls this an instrumental hyperreality.
    • What are the effects of this over:
      • Our society?
      • The environment?
      • Our psychology and overall health?

“Digital devices make hands wither. They mean a liberation from the burden of matter. The human being of the future will no longer need hands. He will no longer need to handle something and work on it, as he will not has to deal more with material things, but only with intangible information. Instead of hands, fingers come in. The new human being passes his fingers [thus, digital], instead of acting. The atrophy of the hands makes him incapable of action.“ – Byung -Chul Han,”In the Swarm”

  • Should there be meaning beyond the digital object? Is there meaning in materiality, embodiment, presence?

“Nothing could be more absurd than to despise the body and yet yearn for its resurrection.” - Wendell Berry